#@adminLayout() #define main()

<body class="gray-bg">
	<div class="ui-layout-west">
		<div class="container-div">
			<div class="row">
				<div class="col-sm-12 search-collapse" id="searchbar">
					<form id="user-formPost">
						<div class="select-list">
							<ul> 
								<li>
									产权：
									<select name="c_pro" id="c_pro" onchange="changeInfo()" >
					           		  #for(data: getOrgInfo(c_pro))
					           		 	<option value="#(data.ccode)">#(data.cname)</option>
					           		  #end
					           		 </select>
								</li>
		                        <li>
		                     		 组名：<input type="text" name="cname" style="width:120px;"/>
									<input type="hidden" name="cdept" id="hf_dept"/>
		                        </li>
		                        
		                        <li>
		                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search('user-formPost','bootstrap-post')"><i class="fa fa-search"></i>&nbsp;搜索</a>
		                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset('user-formPost','bootstrap-post')"><i class="fa fa-refresh"></i>&nbsp;重置</a>
		                        </li>
							</ul>
						</div>
					</form>
				</div>
				
		        <div class="btn-group-sm" id="toolpost" role="group">
		            <a class="btn btn-success" onclick="addPost()" id="btn_adduser">
		                <i class="fa fa-plus"></i> 新增
		            </a>
		            <a class="btn btn-primary single disabled" onclick="editPost()"  id="btn_edituser">
		                <i class="fa fa-edit"></i> 修改
		            </a>
		            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()">
		                <i class="fa fa-remove"></i> 删除
		            </a>
		        </div>
		        
		        <div class="col-sm-12 select-table table-bordered">
				    <table id="bootstrap-post" data-mobile-responsive="true"></table>
				</div>
			</div>
		</div>
	</div>
	
	<div class="ui-layout-center">
		<div class="container-div">
			<div class="row">
				<div class="col-sm-12 search-collapse" id="searchbar2">
					<form id="user-form">
						<div class="select-list">
							<ul> 
		                        <li>
		                     		 用户：<input type="text" name="cname" style="width:120px;"/>
									<input type="hidden" name="cpost" id="hf_ccode"/>
									<input type="hidden" name="c_pro" id="hf_cpro"/>
		                        </li>
		                        <li>
		                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search('user-form','bootstrap-table')"><i class="fa fa-search"></i>&nbsp;搜索</a>
		                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset('user-form','bootstrap-table')"><i class="fa fa-refresh"></i>&nbsp;重置</a>
		                        </li>
							</ul>
						</div>
					</form>
				</div>
				
		        <div class="btn-group-sm" id="toolbar" role="group">
		            <a class="btn btn-success disabled" onclick="addUser()" id="btn_add">
		                <i class="fa fa-plus"></i> 添加人员
		            </a>
		            <a class="btn btn-danger multiple disabled" onclick="removeuserAll()">
		                <i class="fa fa-remove"></i> 删除
		            </a>
		            <span id="post_group"></span>
		        </div>
		        
		        <div class="col-sm-12 select-table table-bordered">
				    <table id="bootstrap-table" data-mobile-responsive="true"></table>
				</div>
			</div>
		</div>
	</div>
	
	
<div class="modal fade" id="add_modal">
	  <div class="modal-dialog">
	    <div class="modal-content">
	      <div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
	        <h4 class="modal-title">岗位组</h4>
	      </div>
	      <div class="modal-body">
	        	<form id="form-config-add" method="post"  class="form-horizontal m" >
					<div class="form-group">
						<label class="col-sm-2 control-label">编码：</label>
						<div class="col-sm-8">
							<input type="hidden" name="ctype" id="ctype" value="edit"/>
							<input id="id" name="ccode" class="form-control" type="text"
								required>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">名称：</label>
						<div class="col-sm-8">
							<input name="cname" class="form-control" type="text"
								required>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">描述：</label>
						<div class="col-sm-8">
							<input name="cdesc" class="form-control" type="text">
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">序号：</label>
						<div class="col-sm-8">
							<input type="number" name="isort" value="1" class="form-control" required/>
						</div>
					</div>
				</form>
	      </div>
	      <div class="modal-footer">
		        <button type="button" class="btn btn-default" data-dismiss="modal">关闭窗口</button>
		        <button type="button" class="btn btn-primary" onclick="saveContent()">保存</button>
		      </div>
	    </div><!-- /.modal-content -->
	  </div><!-- /.modal-dialog -->
</div>
	
	<script type="text/javascript">
		var prefix = "#(ctx)/syspost";
		var c_pro='#(c_pro)';
		$(function() {
			var panehHidden = false;
		    var west__size=450;
		    if ($(this).width() < 769) {
				panehHidden = true;
		    }
		    $('body').layout({ initClosed: panehHidden, west__size: west__size });

		    queryPost();
		    queryList();
			
		});
		
		function queryPost() {
		    var options = {
		    	id:'bootstrap-post',
		    	toolbar:'toolpost',
		        url: prefix + "/list",
	            createUrl: prefix + "/edit",
	            updateUrl: prefix + "/edit?ccode={id}",
	            removeUrl: prefix + "/remove",
	            uniqueId: "ccode",
	            sortName: "cname",
	            sortOrder: "asc",
	            modalName: "岗位组",
                showSearch: false,
                showRefresh: false,
                showColumns: false,
                showToggle: false,
	            columns: [{
	                checkbox: true
	            },{
						title: '序号',//标题  可不加,
	                    width:'50px',
						formatter: function (value, row, index) {
							return index+1;
						}
	             },
                {
                    field: 'ccode',
                    title: '岗位编码',
                    width:'70px'
                },
				{
                    field: 'cname',
                    title: '岗位名称',
                    width: '100px'
                },
                {
                    title: '操作',
                    align: 'center',
                    width: '60px',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="loadPerson(\'' + row.ccode + '\',\'' + row.cname + '\')"><i class="fa fa-edit"></i>人员</a> ');
                        return actions.join('');
                    }
                },]
		    };
		    $.table.init(options);
			
		    $("#bootstrap-post").colResizable({
				liveDrag:true, 
				gripInnerHtml:"<div class='grip'></div>", 
				draggingClass:"dragging", 
	            resizeMode:'overflow'
	        });
		}
		function queryList() {
		    var options = {
		        url: prefix + "/userlist",
	            removeUrl: prefix + "/removeuser",
	            uniqueId: "ccode",
	            sortName: "cname",
	            sortOrder: "asc",
	            modalName: "用户",
                showSearch: false,
                showRefresh: false,
                showColumns: false,
                showToggle: false,
	            columns: [{
	                checkbox: true
	            },{
						title: '序号',//标题  可不加,
	                    width:'50px',
						formatter: function (value, row, index) {
							return index+1;
						}
	             },
                {
                    title: '操作',
                    align: 'center',
                    width: '60px',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="removeuser(\'' + row.ccode + '\',\'' + row.cpost + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        
                        return actions.join('');
                    }
                },
                {
                    field: 'user_num',
                    title: '登录名',
                    width:'100px'
                },
				{
                    field: 'cname',
                    title: '姓名',
                    width: '100px'
                },
				
				{
                    field: 'deptname',
                    title: '所属部门',
                    width: '160px'
                },]
		    };
		    $.table.init(options);
			
		    $("#bootstrap-table").colResizable({
				liveDrag:true, 
				gripInnerHtml:"<div class='grip'></div>", 
				draggingClass:"dragging", 
	            resizeMode:'overflow'
	        });
		}

		//添加
		function addPost()
		{
			var c_pro=$('#c_pro').val();
			if(c_pro=='')
			{
				$.modal.alertError("请选择产权");
				return;
			}
	    	$('#form-config-add')[0].reset();
	    	$("#add_modal").modal({backdrop:true,keyboard:true});
	    	$('#ctype').val('add');
		}
		//编辑
		function editPost()
		{
			var row = $("#bootstrap-post").bootstrapTable('getSelections')[0];
    	    if ($.common.isEmpty(row)) {
    	        $.modal.alertWarning("请至少选择一条记录");
    	        return;
    	    }
	    	$('#form-config-add')[0].reset();
	    	$("#add_modal").modal({backdrop:true,keyboard:true});
			
			$('#form-config-add').loadForm(prefix+'/getData?ccode='+row.ccode);
		}
		//保存
	    function saveContent() {
			var c_pro=$('#c_pro').val();
        	var data=$('#form-config-add').serializeArray();
        	data.push({"name":"c_pro","value":c_pro});
	    	var config = {
		   	        url: prefix+"/save",
		   	     	type: "post",
			        dataType: "json",
		   	        data: data,
		   	        beforeSend: function () {
			        	$.modal.loading("正在处理中，请稍后...");
			        	$.modal.disable();
		   	        },
		   	        success: function(result) {
		   	        	if(result.code==0)
		       			{
		   	        		$.table.search('user-formPost','bootstrap-post');
			   	        	$("#add_modal").modal('hide');
		                }
		   	        	else 
		   	        	{
		                  $.modal.alertError(result.msg);
		                }
		   	        	$.modal.closeLoading();
		   	        }
		   	    };
		   	    $.ajax(config);
	    }
		
		function loadPerson(ccode,cname)
		{
			$('#hf_ccode').val(ccode);
			$('#post_group').text(cname);
			$('#btn_add').removeClass('disabled')
			setTimeout(function(){
				$.table.search('user-form','bootstrap-table');
			},100);
		}
		
		//添加人员信息
		function addUser()
		{
			var c_pro=$('#c_pro').val();
			
			var cpost = $('#hf_ccode').val();
			var url = "#(ctx)/sysuser/selectuser?cpost="+cpost+"&c_pro="+c_pro;
			$.modal.open("选择人员", url);
		}
		
		function removeuserAll()
		{
			var cpost = $('#hf_ccode').val();
			var rows = $.table.selectColumns("ccode");
        	if (rows.length == 0) {
        	    $.modal.alertWarning("请至少选择一条记录");
        	    return;
        	}
        	$.modal.confirm("确认要删除选中的" + rows.length + "条数据吗?", function() {
        	    var data = { "ids": rows.join(),"cpost":cpost};
        	    $.operate.submit(prefix+"/removeuser", "post", "json", data);
        	});
		}

		function removeuser(ccode,cpost)
		{
			$.modal.confirm("确定删除该条用户信息吗？", function() {
				var cpost = $('#hf_ccode').val();
				var data = { "ids": ccode,"cpost":cpost};
	        	$.operate.submit(prefix+"/removeuser", "post", "json", data);
			});
		}
		
		function changeInfo()
		{
			$('#hf_cpro').val($('#c_pro').val());

			$('#btn_add').addClass('disabled')
			$.table.search('user-form','bootstrap-table');
			$.table.search('user-formPost','bootstrap-post')
		}
	</script>
</body>
#end